package com.animee.week03.db;

import com.animee.week03.ResourceTable;
import com.animee.week03.bean.User;
import ohos.agp.components.*;
import ohos.app.Context;

import java.util.List;

public class UserListProvider extends BaseItemProvider {
    Context context;
    List<User>mDatas;
    public UserListProvider(Context context, List<User> mDatas) {
        this.context = context;
        this.mDatas = mDatas;
    }
    @Override
    public int getCount() {return mDatas.size();}
    @Override
    public Object getItem(int i) {return mDatas.get(i);}
    @Override
    public long getItemId(int i) {return i;}

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        if (component == null) {
            component = LayoutScatter.getInstance(context)
                    .parse(ResourceTable.Layout_item_userlist,componentContainer,false);
        }
        Text tv_id = component.findComponentById(ResourceTable.Id_item_usertv_id);
        Text tv_name = component.findComponentById(ResourceTable.Id_item_usertv_name);
        Text tv_phone = component.findComponentById(ResourceTable.Id_item_usertv_tel);
        Text tv_email = component.findComponentById(ResourceTable.Id_item_usertv_email);
        Text tv_info = component.findComponentById(ResourceTable.Id_item_usertv_info);
        User user = mDatas.get(i);
        tv_id.setText(user.getId());
        tv_name.setText(user.getName());
        tv_phone.setText(user.getPhone());
        tv_email.setText(user.getEmail());
        tv_info.setText(user.getInfo());
        return component;
    }
}